package cn.dengta.webapp.user.entity;

import java.util.Date;

import cn.dengta.common.model.State;
import cn.dengta.common.model.ValueProxy;
import cn.dengta.context.model.LabelI18nProxy;
import cn.dengta.context.model.UserEnumI18nKey;
import cn.dengta.webapp.base.entity.BizEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.StringUtil;

/**
 * 头像认证记录表
 *
 * @author lgy
 * @since 2022-03-21
 */
@Setter
@Getter
@Accessors(chain = true)
public class AvatarCertLog extends BizEntity {

	/** 操作用户 */
	private Long userId;
	/** 认证头像 */
	private String avatar;
	/** 请求的IP地址 */
	private String addIp;
	/** 认证结果 */
	private String remark;

	public void setId(Long id) {
		this.id = id;
	}

	public AvatarCertLog() {
	}

	public AvatarCertLog(Long userId, String avatar, String addIp, String remark, Date now) {
		this.userId = userId;
		this.avatar = avatar;
		this.addIp = addIp;
		this.remark = StringUtil.toString(remark);
		super.init(AvatarCertStatus.IN_PROGRESS.value, State.PUBLIC);
		super.initTime(now);
	}

	public enum AvatarCertStatus implements LabelI18nProxy<AvatarCertStatus, Integer> {
		/** 失败 */
		FAIL(-1, UserEnumI18nKey.STATUS_FAIL),
		/** 处理中 */
		IN_PROGRESS(0, UserEnumI18nKey.STATUS_IN_PROGRESS),
		/** 成功 */
		SUCCESS(1, UserEnumI18nKey.STATUS_SUCCESS),
		//
		;

		public final Integer value;
		public final ValueProxy<AvatarCertStatus, Integer> proxy;

		AvatarCertStatus(Integer value, String label) {
			this.value = value;
			this.proxy = new ValueProxy<>(this, value, label);
		}

		public static AvatarCertStatus[] getValues() {
			return ValueProxy.getCachedArray(AvatarCertStatus.class, AvatarCertStatus::values);
		}

		@Override
		public ValueProxy<AvatarCertStatus, Integer> getProxy() {
			return proxy;
		}

		public static AvatarCertStatus of(Integer value) {
			return IN_PROGRESS.getValueOf(value);
		}

		public static AvatarCertStatus ofVerify(boolean yesOrNo) {
			return yesOrNo ? SUCCESS : FAIL;
		}
	}

	public static final String USER_ID = "user_id";
	public static final String AVATAR = "avatar";
	public static final String ADD_IP = "add_ip";
	public static final String REMARK = "remark";

}
